<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/themes/admin/assets/css/layui.css">
    <script src="/themes/admin/assets/layui.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<form class="layui-form">
    {volist name= "ruleList[0]" id="vo"}
    <blockquote class="layui-elem-quote">{$vo.title}</blockquote>
        {notempty name="ruleList[$vo.id]"}
        <div class="layui-form-item">
            <div class="layui-input-block">
                {volist name="ruleList[$vo.id]" id="v"}
                <input type="checkbox" value="{$v.id}" id="{$v.id}" name="ruleItem" title="{$v.title}">
                {/volist}
            </div>
        </div>
    {/notempty}
    {/volist}
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" onclick="saveRule()" class="layui-btn layui-btn-normal">立即提交</button>
            <button type="button" onclick="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
<script>
   (function(){
     layui.use('form')
     layui.use('layer')
    $.ajax({
        type:"POST",
        data:{id:"{$Request.get.id}"},
        url:"/admin/user/ruleDetail",
        success:function (data) {
            $.each(data,function (index,item) {
                $("#"+item).attr("checked","checked");
                layui.form.render('checkbox');	
            })
        }
    })
  })();
  
  var saveRule = function(){
    var ruleIdList = [];
    
      $('input[name="ruleItem"]:checked').each(function(){ 
        ruleIdList.push($(this).val()); 
      }); 
    var data = {"groupId":"{$Request.get.id}","ruleIdList":ruleIdList}
    $.ajax({
    type:"POST",
      data:data,
      url:"/admin/user/saveRule",
      success:function(e){
      if(e.code == 1){
      layer.msg(e.msg);
         }
      }
    });
  }
</script>
</body>
</html>